package gwt.immunology.server.converter;

import static gwt.immunology.shared.GenericDtoKeys.ID;
import static gwt.immunology.shared.GenericDtoKeys.NAME;
import gwt.immunology.shared.GenericDto;
import gwt.immunology.shared.ResultSetDto;

import java.util.List;

import models.Role;

public class RoleDtoConverter {

    public static GenericDto convertRoleToGenericDto(Role role) {
	GenericDto result = new GenericDto();
	if (role != null) {
	    result.put(ID, role.roleId);
	    result.put(NAME, role.roleName);
	}
	return result;
    }

    public static Role convertGenericDtoToRole(GenericDto roleDto) {
	Role result = null;
	if (roleDto != null && !roleDto.isEmpty()) {
	    result = new Role();
	    result.roleId = roleDto.getLong(ID);
	    result.roleName = roleDto.getString(NAME);
	}
	return result;
    }

    public static ResultSetDto convertRolesToResultSetDto(List<Role> roles) {
	ResultSetDto result = new ResultSetDto();
	if (roles != null && !roles.isEmpty()) {
	    for (Role role : roles) {
		GenericDto roleDto = convertRoleToGenericDto(role);
		result.add(roleDto);
	    }
	}
	return result;
    }

}
